package com.fary.boot.autoconfigure.security.servlet;

import com.fary.boot.autoconfigure.condition.ConditionalOnClass;
import com.fary.boot.autoconfigure.condition.ConditionalOnMissingBean;
import com.fary.boot.autoconfigure.security.SecurityDataConfiguration;
import com.fary.boot.autoconfigure.security.SecurityProperties;
import com.fary.boot.context.properties.EnableConfigurationProperties;
import com.fary.context.ApplicationEventPublisher;
import com.fary.context.annotation.Bean;
import com.fary.context.annotation.Configuration;
import com.fary.context.annotation.Import;
import com.fary.security.authentication.AuthenticationEventPublisher;
import com.fary.security.authentication.DefaultAuthenticationEventPublisher;

@Configuration(proxyBeanMethods = false)
// 当引入了spring-security-core包时即自动启用该类
@ConditionalOnClass(DefaultAuthenticationEventPublisher.class)
// 启用配置
@EnableConfigurationProperties(SecurityProperties.class)
// 导入以下几个类，我们知道import即加载实例化类到ioc容器
@Import({SpringBootWebSecurityConfiguration.class, WebSecurityEnablerConfiguration.class, SecurityDataConfiguration.class})
public class SecurityAutoConfiguration {

    // 实例化认证事件发布器
    @Bean
    @ConditionalOnMissingBean(AuthenticationEventPublisher.class)
    public DefaultAuthenticationEventPublisher authenticationEventPublisher(ApplicationEventPublisher publisher) {
        return new DefaultAuthenticationEventPublisher(publisher);
    }

}